package com.ruoyi.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.plus.web.controller.BasePlusController;
import com.ruoyi.common.core.plus.web.page.PageDto;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysLanguageData;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.params.SysLanguageDataParams;
import com.ruoyi.system.service.ISysLanguageDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 语言翻译Controller
 *
 * @author ruoyi
 * @date 2022-04-26
 */
@RestController
@RequestMapping("/system/language_data")
public class SysLanguageDataController extends BasePlusController {
    @Autowired
    private ISysLanguageDataService sysLanguageDataService;

    /**
     * 查询语言翻译列表
     */
    @PreAuthorize("@ss.hasPermi('system:language_data:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLanguageData sysLanguageData) {
        PageDto pageDto = startPage();
        Page<SysLanguageData> page = new Page(pageDto.getCurrentPage(), pageDto.getPageSize());
        Page<SysLanguageData> list = sysLanguageDataService.selectSysLanguageDataList(page,sysLanguageData);
        return getDataTable(list);
    }

    /**
     * 导出语言翻译列表
     */
    @PreAuthorize("@ss.hasPermi('system:language_data:export')")
    @Log(title = "语言翻译", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, SysLanguageData sysLanguageData) throws IOException {
        Page<SysLanguageData> page = new Page<>(1, -1);
        List<SysLanguageData> list = sysLanguageDataService.selectSysLanguageDataList(page,sysLanguageData).getRecords();
        ExcelUtil<SysLanguageData> util = new ExcelUtil<SysLanguageData>(SysLanguageData.class);
        util.exportExcel(response, list, "sysLanguageData");
    }

    /**
     * 获取语言翻译详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:language_data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysLanguageDataService.selectSysLanguageDataById(id));
    }

    /**
     * 新增语言翻译
     */
    @PreAuthorize("@ss.hasPermi('system:language_data:add')")
    @Log(title = "语言翻译", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody SysLanguageDataParams sysLanguageData) {
        return R.ok(sysLanguageDataService.insertSysLanguageData(sysLanguageData));
    }

    /**
     * 修改语言翻译
     */
    @PreAuthorize("@ss.hasPermi('system:language_data:edit')")
    @Log(title = "语言翻译", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody SysLanguageData sysLanguageData) {
        return R.ok(sysLanguageDataService.updateSysLanguageData(sysLanguageData));
    }

    /**
     * 删除语言翻译
     */
    @PreAuthorize("@ss.hasPermi('system:language_data:remove')")
    @Log(title = "语言翻译", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        return R.ok(sysLanguageDataService.deleteSysLanguageDataById(id));
    }

}